/*
 * HublistReader.java
 *
 * Created on 12 November 2006, 14:10
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package hubsniffer.hublist.db;

import hubsniffer.db.DataBaseManager;
import hubsniffer.hublist.Hublist;
import java.io.UnsupportedEncodingException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.LinkedList;

/**
 *
 * @author root
 */
public class HubListFetcher {
    
    private DataBaseManager db;
    
    /** Creates a new instance of HublistReader */
    public HubListFetcher(DataBaseManager db) {
        this.db = db;
    }
    
    public LinkedList<Hublist> getAll() throws SQLException, UnsupportedEncodingException{
        LinkedList<Hublist> all =new LinkedList<Hublist>();
        
        String query = "SELECT * FROM hublist";
        ResultSet res = db.writeQuery(query);
        while(res.next()){
            int id = res.getInt("id");
            String address = res.getString("address");
             int check_count = res.getInt("check_count");
             int online_count = res.getInt("online_count");
             Hublist current = new Hublist(
                     id,
                     address,
                     check_count,
                     online_count
                     );
             
             all.add(current);
        }
        return all;
    }
    
}
